//分享
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:smart_shoes/define/define_colors.dart';
import 'package:smart_shoes/tools/widget_tools.dart';

class MyShare extends StatefulWidget {
  const MyShare({super.key});

  @override
  State<MyShare> createState() => _MyShareState();
}

class _MyShareState extends State<MyShare> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: CustomColors.backgroundColor,
      appBar: AppBar(
        title: const Text('我的分享'),
        // 将 TabBar 放置在 AppBar 的底部
      ),
      body: Container(
        color: CustomColors.backgroundColor,
        child: ListView.builder(
          itemBuilder: (context, index) {
            return _deviceItemView();
          },
          itemCount: 10,
        ),
      ),
    );
  }

  Widget _option() {
    // CustomColors.textColor
    return Row(
      children: [
        Expanded(child: SizedBox(width: 10)),

        SizedBox(width: 12),
        WidgetTools().createCustomInkWellButton(
          "撤销分享",
          () {},
          textColor: CustomColors.textColor,
          buttonWidth: 68,
          height: 26,
          radius: 12.5,
          borderColor: CustomColors.textColor,
          borderWidth: 1,
          shadow: BoxShadow(),
          fontSize: 12,
          bgColor: Colors.white,
        ),

        ///
      ],
    );
  }

  Widget _deviceItemView() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8), // 设置圆角半径为 10
      ),
      margin: EdgeInsets.only(top: 8, left: 12.5, right: 12.5),
      padding: EdgeInsets.only(left: 11.5, right: 11.5, top: 8),
      height: 132.5,
      width: double.infinity,
      child: Column(
        children: [
          //上半部分设备信息
          _deviceInfo(),
          SizedBox(height: 10),
          _option(),
          //下班部分操作按钮
        ],
      ),
    );
  }

  Widget _row(String title, String content) {
    return Row(
      children: [
        Text(
          title,
          style: const TextStyle(
            fontSize: 13,
            color: CustomColors.uncheckedColor,
          ),
        ),
        Expanded(
          child: Text(
            content,
            style: const TextStyle(fontSize: 13, color: CustomColors.textColor),
          ),
        ),
      ],
    );
  }

  Widget _deviceInfo() {
    return Row(
      children: [
        //设备图片
        //设备信息
        _buildDeviceImage(),
        SizedBox(width: 12),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                "李文翰",
                style: const TextStyle(
                  fontSize: 14,
                  color: CustomColors.textColor,
                ),
              ),

              _row('设备编号：', "2341343245"),
              _row('绑定时间：', "2025-03-21 11:32:04"),
            ],
          ),
        ),
        //设备状态
        Text(
          "开启中",
          style: const TextStyle(fontSize: 12, color: CustomColors.statusColor),
        ),
      ],
    );
  }

  Widget _buildDeviceImage() {
    return Container(
      width: 57,
      height: 57,
      child: Image.asset(
        'assets/images/yundongxie.png',
        width: 40.49,
        height: 23,
        fit: BoxFit.fitWidth,
      ),
    );
  }
}
